{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

Used in cases where we have a C++ object defined in Cython code and we need
to create or return a Python object. For complex objects, a Python wrapper
is initialized; for simple objects it can be returned directly. Strings need
to be converted from unicode to binary representation.

}}{{#type:iobuf?}}_fbthrift_iobuf.from_unique_ptr({{field:py_name}}.clone()){{/type:iobuf?}}{{!
}}{{#type:iobufRef?}}_fbthrift_iobuf.from_unique_ptr(move_iobuf({{field:py_name}})){{/type:iobufRef?}}{{!
}}{{#type:flexibleBinary?}}{{!
  }}(<const char*>{{field:py_name}}.data())[:{{field:py_name}}.size()]{{!
}}{{/type:flexibleBinary?}}{{!
}}{{^type:customBinaryType?}}{{!
}}{{#type:bool?}}{{field:py_name}}{{/type:bool?}}{{!
}}{{#type:byte?}}{{field:py_name}}{{/type:byte?}}{{!
}}{{#type:i16?}}{{field:py_name}}{{/type:i16?}}{{!
}}{{#type:i32?}}{{field:py_name}}{{/type:i32?}}{{!
}}{{#type:i64?}}{{field:py_name}}{{/type:i64?}}{{!
}}{{#type:double?}}{{field:py_name}}{{/type:double?}}{{!
}}{{#type:float?}}{{field:py_name}}{{/type:float?}}{{!
}}{{#type:string?}}{{field:py_name}}.data().decode('UTF-8'){{/type:string?}}{{!
}}{{#type:binary?}}{{field:py_name}}{{/type:binary?}}{{!
}}{{#type:structured}}{{!
  }}{{^program:inplace_migrate?}}{{!
    }}{{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
    }}make_shared[{{> types/cython_cpp_type}}]({{field:py_name}})){{!
  }}{{/program:inplace_migrate?}}{{#program:inplace_migrate?}}{{!
    }}{{> types/python_type }}.from_python({{!
    }}{{type:capi_converter_path}}.{{struct:name}}_from_cpp({{!
    }}deref_const[{{> types/cython_cpp_type }}]({{field:py_name}}))){{!
  }}{{/program:inplace_migrate?}}{{!
}}{{/type:structured}}{{!
}}{{#type:container?}}{{!
  }}{{> types/container_from_cpp}}({{field:py_name}}){{!
}}{{/type:container?}}{{!
}}{{#type:enum?}}{{> types/python_type}}(<int> {{field:py_name}}){{/type:enum?}}{{!
}}{{/type:customBinaryType?}}
